package middlewares

import (
	"gitee.com/xgotool/backend-framework-template/service/users"
	"github.com/gin-gonic/gin"
)

// 后台权限验证中间件
// 该中间件验证前，已验证用户的登录权限，所以此处可直接拿用户ID进行权限验证
func MustAdmin(c *gin.Context) {
	mids, err := users.MenuId(c.GetUint("uid"))
	if err != nil || len(mids) == 0 {
		c.JSON(401, gin.H{
			"flag": false,
			"msg":  "无权限",
		})
		c.Abort()
		return
	}
	c.Next()
}
